home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / comnumb.exe / COMPOUN.H < prev    next >
C/C++ Source or Header  |  1992-05-01  |  2KB  |  59 lines

  1. //////////////////////////////////////////////////////////////////////
  2. // compoun.h: Compound number class definition.
  3. // Copyright (c) 1992 Azarona Software. All rights reserved.
  4. //////////////////////////////////////////////////////////////////////
  5. #ifndef H_COMPOUND
  6. #define H_COMPOUND
  7. #include "rational.h"
  8.  
  9. class Compound {
  10. private:
  11.   long w;     // Whole number part
  12.   Rational f; // Fractional part
  13. public:
  14.   // Constructors and assignment
  15.   Compound();
  16.   Compound(long n);
  17.   Compound(long n, Rational &r);
  18.   Compound(Compound const &c);
  19.   Compound &operator=(Compound const &c);
  20.   // Helper functions
  21.   void Simplify();
  22.   void Set(long n, Rational &r);
  23.   void Invert();
  24.   void Negate();
  25.   int IsUndefined() const;
  26.   int IsNegative() const;
  27.   int IsPositive() const;
  28.   int IsZero() const;
  29.   // Stream I/O operators
  30.   friend istream &operator>>(istream &s, Compound &c);
  31.   friend ostream &operator<<(ostream &s, const Compound &c);
  32.   // Arithmetic operators that modify their operand
  33.   Compound operator++(int); // Postfix
  34.   Compound operator--(int); // Postfix
  35.   Compound &operator++();   // Prefix
  36.   Compound &operator--();   // Prefix
  37.   Compound &operator+=(const Compound &r);
  38.   Compound &operator-=(const Compound &r);
  39.   Compound &operator*=(const Compound &r);
  40.   Compound &operator/=(const Compound &r);
  41.   // Arithmetic operators resulting in new object
  42.   Compound operator-() const;
  43.   Compound operator+() const;
  44.   friend Compound operator+(const Compound &a, const Compound &b);
  45.   friend Compound operator-(const Compound &a, const Compound &b);
  46.   friend Compound operator*(const Compound &a, const Compound &b);
  47.   friend Compound operator/(const Compound &a, const Compound &b);
  48.   // Comparison operators
  49.   friend int operator==(const Compound &a, const Compound &b);
  50.   friend int operator!=(const Compound &a, const Compound &b);
  51.   friend int operator<(const Compound &a, const Compound &b);
  52.   friend int operator<=(const Compound &a, const Compound &b);
  53.   friend int operator>(const Compound &a, const Compound &b);
  54.   friend int operator>=(const Compound &a, const Compound &b);
  55. };
  56.  
  57. #endif
  58.  
  59.